package com.ebring.shareEducation.service.impl;

import com.ebring.shareEducation.bean.Task;
import com.ebring.shareEducation.bean.Ustaccount;
import com.ebring.shareEducation.dao.UstAccountMapper;
import com.ebring.shareEducation.service.UstAccountService;
import com.ebring.shareEducation.utils.RspMsg;
import com.ebring.shareEducation.utils.UuidUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


@Service
@Transactional
public class UstAccountServiceImpl implements UstAccountService {

	@Autowired
	private UstAccountMapper ustAccountMapper;


	@Override
	public RspMsg selectUstaccountbyuserid(String userId) {
		RspMsg rspMsg = new RspMsg();
		Ustaccount ustaccount = ustAccountMapper.selectPayUserid(userId);
		if(ustaccount!=null){
			rspMsg.setOK();
			rspMsg.setResult(ustaccount);
		}else{
			rspMsg.setError();
			rspMsg.setMsg("查询不到数据");
		}
		return rspMsg;
	}

	// 查询所有的菜单
	@Override
	public RspMsg<Ustaccount> selectust() {
		RspMsg rspMsg = new RspMsg();
		Map<String, Object> map = new LinkedHashMap<>();
		List<Ustaccount> ustlist=ustAccountMapper.selectAll();
		if (ustlist.isEmpty() || ustlist == null) {
			rspMsg.setOK();
			rspMsg.setMsg("未找到相关任务");
			return rspMsg;
		}
		map.put("ustlist",ustlist);
		rspMsg.setOK();
		rspMsg.setResult(map);
		return rspMsg;
	}

	// 修改菜单
	@Override
	public RspMsg<Ustaccount> updateUst(Ustaccount ustaccount) {
		RspMsg rspMsg = new RspMsg();
		int i = ustAccountMapper.updateByPrimaryKeySelective(ustaccount);
		if (i == 0) {
			rspMsg.setError();
			rspMsg.setMsg("修改失败");
			return rspMsg;
		}
		rspMsg.setOK();
		return rspMsg;

	}

	@Override
	@Transactional
	public RspMsg<Ustaccount> insertust(String userid,String bid) {
		RspMsg rspMsg = new RspMsg();
		Ustaccount ustaccount=new Ustaccount();
		ustaccount.setId(UuidUtils.getNumberId(6));
		ustaccount.setUserid(userid);
		ustaccount.setBid(bid);
		int i = ustAccountMapper.insertSelective(ustaccount);
		if (i == 0) {
			rspMsg.setError();
			rspMsg.setMsg("新增失败");
			return rspMsg;
		}
		rspMsg.setOK();
		rspMsg.setMsg("新增成功");
		return rspMsg;
	}
}
